# Copyright (c) 2011 Peter Shinners

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

import nose
raise nose.SkipTest()


import os
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

import unittest
from minivec import Box
import minivec


class TestBounds(unittest.TestCase):
    def setUp(self):
        minivec.ResetError()
        minivec.ResetEpsilon()


    def TestConstructors(self):
        "Various forms of constructors"
        onesA = Box(1, 1, 1, 1, 1, 1)
        onesB = Box((1, 1, 1, 1, 1, 1))
        onesC = Box((1, 1, 1), 1)
        onesD = Box(onesA)
        
        self.assertEqual(onesA, onesB)
        self.assertEqual(onesA, onesC)
        self.assertEqual(onesB, onesC)
        self.assertEqual(onesA, onesD)

        
    def TestBadConstructors(self):
        "Constructors that should fail"
        self.assertRaises(TypeError, lambda: Box("bounds"))
        self.assertRaises(TypeError, lambda: Box("1.0"))
        self.assertRaises(TypeError, lambda: Box((1, 2, 3, 4)))
        self.assertRaises(TypeError, lambda: Box((1, 1, 1), (2, 2, 2, 2)))
        self.assertRaises(TypeError, lambda: Box(1, 2, 3, 4))
        self.assertRaises(TypeError, lambda: Box(1j))
        self.assertRaises(TypeError, lambda: Box(1, 2j, 3, 4, 5))


    def TestNonzero(self):
        "Truthness of vectors"
        # TODO
        pass


    def TestEquality(self):
        "Equality and inequality"
        # TODO
        pass
        # Ensure hashing works for sets and dictionaries
        # Cannot compare with scalars
        # Test sloppy epsilon equality


    def TestAlmost(self):
        """Test equality with epsilon"""
        # TODO
        pass

        
    def TestExact(self):
        "Test equality without epsilon"
        # TODO
        pass


    def TestSequence(self):
        "Sequence style access"
        a = Box(1, 2, 3, 4, 5, 6)

        self.assertEqual(a[0], 1.0)
        self.assertEqual(a[1], 2.0)
        self.assertEqual(a[2], 3.0)
        self.assertEqual(a[-1], 6.0)
        self.assertEqual(a[-2], 5.0)
        self.assertEqual(a[-3], 4.0)
        self.assertEqual([v for v in a], [1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
        self.assertEqual(max(a), 6.0)
        self.assertEqual(any(a), True)
        self.assertEqual(a[:2], (1.0, 2.0))
        self.assertEqual(a[1:], (2.0, 3.0, 4.0, 5.0, 6.0))
        self.assertEqual(a[6:], ())


    def TestSubclass(self):
        "Ensure the subclass is preserved"
        class SuperBound(Box):
            pass

        a = SuperBound(1, 2, 3, 4, 5, 6)
        b = SuperBound(12)
        self.assertTrue(isinstance(b.resize(3, 3, 3), SuperBound))
        self.assertTrue(isinstance(a.expand(b), SuperBound))


    def TestLerp(self):
        # TODO
        pass


    def TestExpand(self):
        # TODO
        pass


    def TestCorners(self):
        # TODO
        # and center
        pass


    def TestLength(self):
        # TODO
        # and size
        pass
    
    
    def assertAlmostBound(self, first, second):
        if not first.almost(second):
            raise self.failureException, \
                  ('%r !~= %r' % (first, second))


if __name__ == "__main__":
    unittest.main()
